package com.zuthub.web.controller.system;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.zuthub.common.annotation.Log;
import com.zuthub.common.core.controller.BaseController;
import com.zuthub.common.core.domain.AjaxResult;
import com.zuthub.common.enums.BusinessType;
import com.zuthub.system.domain.SysSponsor;
import com.zuthub.system.service.ISysSponsorService;
import com.zuthub.common.utils.poi.ExcelUtil;
import com.zuthub.common.core.page.TableDataInfo;

/**
 * 赞助商管理Controller
 * 
 * @author zuthub
 * @date 2021-04-02
 */
@RestController
@RequestMapping("/system/sponsor")
public class SysSponsorController extends BaseController
{
    @Autowired
    private ISysSponsorService sysSponsorService;

    /**
     * 查询赞助商管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:sponsor:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysSponsor sysSponsor)
    {
        startPage();
        List<SysSponsor> list = sysSponsorService.selectSysSponsorList(sysSponsor);
        return getDataTable(list);
    }

    @GetMapping("/tourist")
    @CrossOrigin
    public TableDataInfo listForTourist(SysSponsor sysSponsor)
    {
        startPage();
        List<SysSponsor> list = sysSponsorService.selectSysSponsorList(sysSponsor);
        return getDataTable(list);
    }

    /**
     * 导出赞助商管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:sponsor:export')")
    @Log(title = "赞助商管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SysSponsor sysSponsor)
    {
        List<SysSponsor> list = sysSponsorService.selectSysSponsorList(sysSponsor);
        ExcelUtil<SysSponsor> util = new ExcelUtil<SysSponsor>(SysSponsor.class);
        return util.exportExcel(list, "sponsor");
    }

    /**
     * 获取赞助商管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:sponsor:query')")
    @GetMapping(value = "/{sponsorId}")
    public AjaxResult getInfo(@PathVariable("sponsorId") Long sponsorId)
    {
        return AjaxResult.success(sysSponsorService.selectSysSponsorById(sponsorId));
    }

    /**
     * 新增赞助商管理
     */
    @PreAuthorize("@ss.hasPermi('system:sponsor:add')")
    @Log(title = "赞助商管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysSponsor sysSponsor)
    {
        return toAjax(sysSponsorService.insertSysSponsor(sysSponsor));
    }

    /**
     * 修改赞助商管理
     */
    @PreAuthorize("@ss.hasPermi('system:sponsor:edit')")
    @Log(title = "赞助商管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysSponsor sysSponsor)
    {
        return toAjax(sysSponsorService.updateSysSponsor(sysSponsor));
    }

    /**
     * 删除赞助商管理
     */
    @PreAuthorize("@ss.hasPermi('system:sponsor:remove')")
    @Log(title = "赞助商管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{sponsorIds}")
    public AjaxResult remove(@PathVariable Long[] sponsorIds)
    {
        return toAjax(sysSponsorService.deleteSysSponsorByIds(sponsorIds));
    }
}
